package com.leoman.spinningmachine.tab1;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import com.leoman.helper.util.AppManager;
import com.leoman.helper.util.ToastUtil;
import com.leoman.spinningmachine.R;
import com.leoman.spinningmachine.base.BaseActivity;
import com.leoman.spinningmachine.constant.Constant;
import com.leoman.spinningmachine.tab3.CardRecordActivity;
import com.leoman.spinningmachine.util.SharedPreferencesUtils;

import butterknife.BindView;

/**
 * 全部功能
 */
public class AllFunctionActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    @BindView(R.id.gridView)
    GridView gridView;

    private FunctionAdapter adapter;
    private int[] icons = {R.drawable.ic_function1, R.drawable.ic_function2, R.drawable.ic_function3, R.drawable.ic_function4,
            R.drawable.ic_function5, R.drawable.ic_function9, R.drawable.ic_function6, R.drawable.ic_function7};
    private String[] names = {"新闻动态", "考勤打卡", "请假审批", "安防系统", "门禁系统", "停车系统", "链接OA", "链接ERP"};

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.ac_all_function;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        AppManager.getInstance().addActivity(this);
        initTitle("全部功能");
    }

    @Override
    protected void initData() {
        adapter = new FunctionAdapter(this, icons, names);
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        switch (i) {
            case 0://新闻动态
                gotoOtherActivity(NewsActivity.class);
                break;
            case 1://考勤打卡
                gotoOtherActivity(CardRecordActivity.class);
                break;
            case 2://请假审批
                gotoOtherActivity(AskLeaveActivity.class);
                break;
            case 3://安防系统
                int cameraq = SharedPreferencesUtils.getInstance().getInt(Constant.CAMERAQ);
                if (cameraq == 1) {
                    gotoFlagTitleActivity(NoFunActivity.class, "安防系统", 1);
                } else {
                    ToastUtil.showToast(this, "暂无权限，请联系后台管理人员添加", Toast.LENGTH_SHORT);
                }
                break;
            case 4://门禁系统
                gotoOtherActivity(EntranceGuardActivity.class);
                break;
            case 5://停车系统
//                gotoFlagTitleActivity(NoFunActivity.class,"停车系统",4);
                break;
            case 6://链接OA
//                gotoFlagTitleActivity(NoFunActivity.class,"链接OA",2);
                break;
            case 7://链接ERP
//                gotoFlagTitleActivity(NoFunActivity.class,"链接ERP",3);
                break;

        }
    }
}
